import Vue      from 'vue'
import Router   from 'vue-router'

import Home          from "../view/home"
import Index         from '../view/index/index'
import Plan          from '../view/model/plan/index'
import File          from '../view/model/file/index'
import Article       from '../view/model/article/index'
import ArtView       from '../view/model/article/view'
import IndexArtView  from '../view/model/article/view'
import Picture       from '../view/model/picture/index'
import MdEditor      from '../view/model/md/mdEditor'
import NotFound      from '../view/error/404'

Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'hash',
  scrollBehavior (to, from, savedPosition) {
    if(savedPosition) {
      return savedPosition
    } else {
      return  {
        x: 0,
        y: 0
      }
    }
  },
  routes: [

    {
      path: '/bjstk',
      name: 'bjstk',
      component: Home,
      children : [
        {
          path: 'index',
          name: 'index',
          component: Index,
          meta: {
            keepalive: true
          }
        },{
          path: 'plan',
          name: 'plan',
          component: Plan,
          meta: {
            keepalive: true
          }
        },{
          path: 'file',
          name: 'file',
          component: File,
          meta: {
            keepalive: true
          }
        },{
          path: 'picture',
          name: 'picture',
          component: Picture,
          meta: {
            keepalive: true
          }
        },{
          path: 'article',
          name: 'article',
          component: Article,
          meta: {
            keepalive: true
          }
        },{
          path: 'artView',
          name: 'artView',
          component: ArtView,
          meta: {
            keepalive: true
          }
        },{
          path: 'md',
          name: 'md',
          component: MdEditor,
          meta: {
            keepalive: false
          }
        },
        {
          path: '*',
          name: 'notfound',
          component: NotFound
        }
      ]
    },
    {
      path: '/indexArtView/:articleId',
      name: 'indexArtView',
      component: IndexArtView
    }
  ]
})
